﻿using System;
using System.Collections.Generic;
using System.Linq;
using AB.ServiceDirectory.Commons.DataFilters;
using AB.ServiceDirectory.Dao;
using AB.ServiceDirectory.Entities;

namespace AB.ServiceDirectory.BO
{
    [Serializable]
    public static class AContactBO
    {
        /// <summary>
        /// Prevents a default instance of the <see cref="AContactBO"/> class from being created.
        /// </summary>
        private static readonly AContactDao Dao = new AContactDao();

        /// <summary>
        /// Finds all contacts.
        /// </summary>
        /// <returns></returns>
        public static ICollection<Contact> FindAllContacts()
        {
            return Dao.FindAllContacts().ToList();
        }

        /// <summary>
        /// Searches the contact.
        /// </summary>
        /// <param name="firstName">The first name.</param>
        /// <param name="surname">Name of the sur.</param>
        /// <returns></returns>
        public static ICollection<Contact> SearchContact(string firstName, string surname)
        {
            return Dao.SearchContact(firstName, surname);
        }

        /// <summary>
        /// Checks the email existed.
        /// </summary>
        /// <param name="email">The email.</param>
        /// <returns></returns>
        public static bool CheckEmailExisted(string email)
        {
            return Dao.CheckEmailExisted(email);
        }

        /// <summary>
        /// Adds the contact.
        /// </summary>
        /// <param name="contact">The contact.</param>
        /// <returns></returns>
        public static bool AddContact(Contact contact)
        {
            return Dao.AddContact(contact);
        }

        /// <summary>
        /// Edits the contact.
        /// </summary>
        /// <param name="contact">The contact.</param>
        /// <returns></returns>
        public static bool EditContact(Contact contact)
        {
            return Dao.EditContact(contact);
        }

        /// <summary>
        /// Finds the contact by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public static Contact FindContactById(int id)
        {
            return Dao.FindContactById(id);
        }

        // TEST - HuanNN1
        // GIải thích bên DAO
        public static IQueryable<Contact> GetList(AContactFilter filter, string sortType, int startRowIndex, int maxRows)
        {
            return Dao.GetList(filter, sortType, startRowIndex, maxRows);
        }

        public static int GetListCount(AContactFilter filter)
        {
            return Dao.GetListCount(filter);
        }
    }
}